package com.lin.security;

import com.lin.base.ResultCode;
import com.lin.util.ResponseMessageUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;

/**
 * @author linze
 * @version 1.0
 * @Description
 * @Date 2021/1/21 18:03
 */
@Component
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        //没有登入时(或无token)处理方法
        System.out.println("认证失败：" + e.getMessage());
        ResponseMessageUtils.setFailMessage(httpServletResponse, ResultCode.UNAUTHORIZED,"没有权限访问,未登入或者登入token校验失败");

    }
}
